﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;

namespace TerrariaSVCv2 {
    public partial class TerrariaSVCv2 : ServiceBase {
        Worker workerObject;
        WorkerArgs wArgs;
        Thread workerThread;

        public TerrariaSVCv2() {
            InitializeComponent();
        }

        protected override void OnStart(string[] args) {                        
            workerObject = new Worker();
            workerThread = new Thread(workerObject.StartService);

            workerObject.onPlayerJoin += new Worker.PlayerJoin(workerObject_onPlayerJoin);
            workerObject.onPlayerChat += new Worker.PlayerChat(workerObject_onPlayerChat);
            workerObject.onPlayerLeft += new Worker.PlayerLeft(workerObject_onPlayerLeft);
            workerObject.onServerMessage += new Worker.ServerMessage(workerObject_onServerMessage);

#warning "We're not really using the WorkerArgs at this time"
            wArgs = new WorkerArgs();

            workerThread.Start(wArgs);
        }

        void workerObject_onServerMessage(string message) {
            throw new NotImplementedException();
        }

        void workerObject_onPlayerLeft(string username) {
            throw new NotImplementedException();
        }

        void workerObject_onPlayerChat(string username, string message) {
            throw new NotImplementedException();
        }

        void workerObject_onPlayerJoin(string username) {
            throw new NotImplementedException();
        }

        protected override void OnStop() {
            workerObject.SaveWorld();            
            workerObject.SendChat("Shutting down! Come back again!");
        }
                
    }
}
